package com.acwing.partition1;

import java.io.*;
import java.util.Arrays;

/**
 * @author `RKC`
 * @date 2021/11/28 18:02
 */
public class AC91最短Hamilton路径 {

    private static final int N = 20, INF = 0x3f3f3f3f;
    private static int[][] g = new int[N][N], f = new int[1 << N][N];
    private static int n;

    private static StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    private static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        n = nextInt();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                g[i][j] = nextInt();
            }
        }
        writer.println(resolve());
        writer.flush();
    }

    private static int resolve() {
        for (int i = 0; i < 1 << n; i++) Arrays.fill(f[i], INF);
        f[1][0] = 0;
        for (int s = 0; s < 1 << n; s++) {
            for (int i = 0; i < n; i++) {
                if ((s >> i & 1) == 0) continue;
                for (int j = 0; j < n; j++) {
                    if ((s >> j & 1) == 1) continue;
                    f[s | 1 << j][j] = Math.min(f[s | 1 << j][j], f[s][i] + g[i][j]);
                }
            }
        }
        return f[(1 << n) - 1][n - 1];
    }

    private static int nextInt() throws IOException {
        tokenizer.nextToken();
        return (int) tokenizer.nval;
    }
}
